import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '下单时间',
    align: 'center',
    dataIndex: 'orderCreateTime',
    width: 105,
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
  {
    title: '订单编号',
    align: 'center',
    dataIndex: 'orderId',
    width: 122,
  },
  {
    title: '机器编号',
    align: 'center',
    dataIndex: 'machineId',
    width: 122,
  },

  {
    title: '出口地',
    align: 'center',
    dataIndex: 'orderArea',
    width: 100,
  },
  {
    title: '交货时间',
    align: 'center',
    width: 120,
    dataIndex: 'planFinishedTime',
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
  {
    title: '机器类别',
    align: 'center',
    width: 100,
    dataIndex: 'type',
  },
  {
    title: '数量',
    align: 'center',
    width: 80,
    dataIndex: 'num',
  },
  {
    title: '生产进度',
    align: 'center',
    width: 100,
    dataIndex: 'status',
  },
  {
    title: '质检时间',
    align: 'center',
    dataIndex: 'testTime',
    width: 100,
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
  {
    title: '发货日期',
    align: 'center',
    width: 105,
    dataIndex: 'finishedTime',
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '订单号',
    field: 'orderId',
    component: 'Input', //TODO 范围查询
    colProps: { span: 4 },
  },

  {
    label: '出口地',
    field: 'orderArea',
    component: 'Input', //TODO 范围查询
    colProps: { span: 4 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '订单编号',
    field: 'orderId',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入订单编号!' }];
    },
  },
  {
    label: '机器编号',
    field: 'machineId',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入机器编号!' }];
    },
  },
  {
    label: '下单时间',
    field: 'orderCreateTime',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入下单时间!' }];
    },
  },
  {
    label: '出口地',
    field: 'orderArea',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入出口地!' }];
    },
  },
  {
    label: '交货时间',
    field: 'planFinishedTime',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入约定交货时间!' }];
    },
  },
  {
    label: '机器类别',
    field: 'type',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入机器类别!' }];
    },
  },
  {
    label: '规格型号',
    field: 'ype2',
    component: 'Input',
  },
  {
    label: '数量',
    field: 'num',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入数量!' }];
    },
  },
  {
    label: '图片',
    field: 'productImg',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 0,
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  orderId: { title: '订单编号', order: 0, view: 'text', type: 'string' },
  machineId: { title: '机器编号', order: 1, view: 'text', type: 'string' },
  orderCreateTime: { title: '下单时间', order: 2, view: 'date', type: 'string' },
  orderArea: { title: '出口地', order: 3, view: 'text', type: 'string' },
  planFinishedTime: { title: '约定交货时间', order: 4, view: 'date', type: 'string' },
  type: { title: '机器类别', order: 5, view: 'text', type: 'string' },
  num: { title: '数量', order: 7, view: 'number', type: 'number' },
  status: { title: '生产进度', order: 8, view: 'text', type: 'string' },
  testTime: { title: '质检完成时间', order: 9, view: 'date', type: 'string' },
  finishedTime: { title: '发货日期', order: 10, view: 'date', type: 'string' },
  productImg: { title: '图片', order: 11, view: 'image', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
